package luit.mmt02.activity;

import luit.mmt02.R;
import luit.mmt02.dataAccess.db_econtact;
import luit.mmt02.doituong.showToast;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class add_new_contact extends Activity
{
	String email,name;
	EditText txtemail, txtname;
	db_econtact mydb;
	showToast st;
	int requestCode = 0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_new_contact);
		txtemail = (EditText) findViewById(R.id.txt_add_newcontact_email);
		txtname = (EditText) findViewById(R.id.txt_add_newcontact_name);
		mydb = new db_econtact(this);
		st = new showToast(this);
	}
	
	public void btn_onClick(View v)
	{
		Button btn = (Button)v;
		switch (btn.getId()) {
		case R.id.btn_add_newcontact_OK:
			if(txtemail.getText().toString().trim().length() > 0 && txtname.getText().toString().trim().length() > 0)
				add_contact();
			else
			{
				st.showmess(getResources().getString(R.string.email_err_blank));
			}
			break;
		case R.id.btn_add_newcontact_cancel:
			finish();
//			startActivityForResult((new Intent(this, get_econtact_Activity.class)),requestCode);
			break;
		default:
			break;
		}
	}
	public void add_contact()
	{
		try {
			name = txtname.getText().toString();
			email = txtemail.getText().toString().trim();
			mydb.add_econtact(name, email);
			st.showmess("them email thanh cong ");
//			startActivity(new Intent(this, get_econtact_Activity.class));
			setResult(RESULT_OK);
			finish();
		} catch (Exception e) {
			// TODO: handle exception
			Log.v("addnewcontact", "err add new contact" +e.toString());
		}
	}
	
}
